<template>
  <div class="login">
    <div class="tabs">
      <div class="tab active">登录</div>
      <router-link to="/register" class="tab">注册</router-link>
    </div>
    <form @submit.prevent="handleLogin">
      <div class="form-group">
        <label>邮箱地址</label>
        <input v-model="email" type="email" required placeholder="请输入邮箱地址" />
      </div>
      <div class="form-group">
        <label>密码</label>
        <input v-model="password" type="password" required placeholder="请输入密码" />
      </div>
      <button type="submit">登录</button>
    </form>
    <p class="form-footer">还没有账号？<router-link to="/register">立即注册</router-link></p>
  </div>
</template>

<script lang="ts">
import { defineComponent, ref } from 'vue';
import { useRouter } from 'vue-router';

export default defineComponent({
  name: 'LoginView',
  setup() {
    const router = useRouter();
    const email = ref('');
    const password = ref('');
    
    const handleLogin = () => {
      // 登录逻辑
      console.log('登录:', email.value);
      // 模拟登录成功
      localStorage.setItem('isLoggedIn', 'true');
      localStorage.setItem('userEmail', email.value);
      router.push('/');
    };
    
    return {
      email,
      password,
      handleLogin
    };
  }
});
</script>

<style scoped>
.login {
  max-width: 400px;
  margin: 0 auto;
  padding: 2rem;
  background-color: white;
  border-radius: 8px;
  box-shadow: 0 2px 10px rgba(0,0,0,0.1);
}

.tabs {
  display: flex;
  margin-bottom: 2rem;
  border-bottom: 1px solid #eee;
}

.tab {
  padding: 0.75rem 1.5rem;
  cursor: pointer;
  color: #666;
  text-decoration: none;
  font-weight: 500;
}

.tab.active {
  color: #007acc;
  border-bottom: 2px solid #007acc;
}

.form-group {
  margin-bottom: 1.5rem;
}

.form-group label {
  display: block;
  margin-bottom: 0.5rem;
  font-weight: 500;
  color: #333;
}

.form-group input {
  width: 100%;
  padding: 0.75rem;
  border: 1px solid #ddd;
  border-radius: 4px;
  font-size: 1rem;
}

button {
  width: 100%;
  padding: 0.75rem;
  margin-top: 1rem;
  background-color: #007acc;
  color: white;
  border: none;
  border-radius: 4px;
  font-size: 1rem;
  cursor: pointer;
  transition: background-color 0.3s;
}

button:hover {
  background-color: #0062a3;
}

.form-footer {
  margin-top: 1.5rem;
  text-align: center;
  color: #666;
}
</style>